//https://zhuanlan.zhihu.com/p/346930154

#include <8052.h>
#include "IRReceiver.h"

#include "L298N.h"

void L298N_Delay1000ms() //@11.0592MHz
{
    unsigned char i, j, k;
    i = 8;
    j = 1;
    k = 243;
    do
    {
        do
        {
            while (--k)
                ;
        } while (--j);
    } while (--i);
}
//红外回调方法
//检测出来的编码 IRReceiver_Record[2]
//1:    0b01000100
//2:    0b01000110
//3:    0b01000110
//4:    0b01000100
//5:    0b01000000
//6:    0b01000010
//7:    0b00000110
//8:    0b00010100
//9:    0b00001000
//0:    0b00011000
//*:    0b00010110
//#:    0b00001100
//上：  0b00011000
//下：  0b01010010
//左：  0b00001000
//右：  0b01011010
//ok:   0b00011100
void L298N_IRReceiver_Callback(char data)
{

    if (data == 0b00001000 || data == 0b01010010)
    { //左或下
        P1_3 = 1;
        P1_4 = 0;
    }
    else if (data == 0b01011010 || data == 0b00011000)
    { //右或上
        P1_3 = 0;
        P1_4 = 1;
    }
    else if (data == 0b00011100)
    { //ok：
        P1_3 = 1;
        P1_4 = 1;
    }
}

void L298N_Test()
{
    IRReceiver_Test(L298N_IRReceiver_Callback);
}
